﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CloudClass.Models;
using Orchard.Data;

namespace CloudClass.Services
{
    public class CourseInfoService:ICourseInfoService
    {
        private readonly IRepository<CourseInfo> _courseRepository;
        //private readonly IEnumerable<ICarEventHandler> _handlers; 
        public CourseInfoService(IRepository<CourseInfo> carRepository)
        {
            _courseRepository = carRepository;
            //_handlers = handlers;
        }

        public virtual bool Create(Models.CourseInfo model)
        {

            try
            {
                _courseRepository.Create(model);
            }
            catch
            {
                return false;
            }
            return true;
        }

        public virtual bool Edit(CourseInfo model)
        {
            try
            {
                _courseRepository.Update(model);
            }
            catch
            {
                return false;
            }
            return true;
        }

        public virtual bool Delete(int[] array)
        {
            try
            {
                foreach (var id in array)
                {
                    var item = this.Get(id);
                    _courseRepository.Delete(item);
                }
            }
            catch
            {
                return false;
            }
            return true;
        }

        public virtual CourseInfo Get(int id)
        {
            var item = _courseRepository.Get(id);
            return item;
        }

        public virtual List<CourseInfo> GetList()
        {
            return _courseRepository.Table.ToList();
        }

       
    }
}